package demoMod.stsconsole.commands;

import demoMod.stsconsole.dungeons.AbstractDungeon;
import demoMod.stsconsole.enums.ErrType;
import demoMod.stsconsole.rooms.EventRoom;

import java.util.Scanner;

public class Event extends AbstractCommand {
    @Override
    public void execute(String[] args, Scanner sc) {
        if (args.length != 1) {
            this.errMsg(ErrType.WRONG_ARGUMENT);
            return;
        }
        int optionIndex;
        try {
            optionIndex = Integer.parseInt(args[0]);
        } catch (NumberFormatException e) {
            this.errMsg(ErrType.WRONG_ARGUMENT);
            return;
        }
        if (optionIndex < 0 || optionIndex >= ((EventRoom) AbstractDungeon.currDungeon.currMapNode.room).getEvent().getCurrNode().getOptionSize()) {
            this.errMsg(ErrType.WRONG_ARGUMENT);
            return;
        }
        ((EventRoom) AbstractDungeon.currDungeon.currMapNode.room).getEvent().onChooseOption(optionIndex);
    }

    @Override
    public boolean requiredPrompt(String currentPrompt) {
        return "Dungeon/Event/".equals(currentPrompt);
    }
}
